package com.scalar.chiptrack.operations.inventoryps.forms;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionMapping;

import com.scalar.chiptrack.ChipTrackActionForm;
import com.scalar.chiptrack.commons.Address;
import com.scalar.chiptrack.commons.ClientInfo;
import com.scalar.chiptrack.operations.dataentry.LotDetails;
import com.scalar.chiptrack.operations.packingslip.forms.PackingSlipForm;
import com.scalar.chiptrack.utils.AutoGrowingArrayList;

public class InventoryPackingSlipForm  extends ChipTrackActionForm
{
	private String processType	= null;
	private String baseprocessType	= null;
    private int processStepId   = -1;
    private int locationId      = -1;
    private int lotId    		= -1;
    private int toVendorId    	= -1;
	private Address fromAddress = null;
	private Address toAddress 	= null;
	private String noOfBoxes 		= null;
	private String grossWeight  = null;
	private String wayBillNo	= null;
	private String shipDate 	= null;
	private String shippingMethod 	= null;
	private String shippingAccount 	= null;
	private String fromVendorName 	= null;
	private String toVendorName 	= null;
	private String packingSlipNumber = null;
	private String status = null;
	private int packingSlipId = -1;
	private String splInstructions = null;
    private ClientInfo clientInfo = null;

	ArrayList<LotDetails> selectedLotsList = new AutoGrowingArrayList( LotDetails.class );
    ArrayList<LotDetails> availableLotsList = new AutoGrowingArrayList( LotDetails.class );


    public String getStatus() {
		return status;
	}

    public String getFromAddressAsString() {
		return fromAddress.getAddressAsString();
	}

    public String getToAddressAsString() {
		return toAddress.getAddressAsString();
	}

    public void setStatus(String status) {
		this.status = status;
	}

	public ArrayList<LotDetails> getAvailableLotsList() {
		return availableLotsList;
	}

	public void setAvailableLotsList(ArrayList<LotDetails> availableLotsList) {
		this.availableLotsList = availableLotsList;
	}

	public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest)
    {
        if( availableLotsList != null )
        {
           for(int i=0; i< availableLotsList.size(); i++ )
           {
        	   LotDetails lotDetails = ( LotDetails)availableLotsList.get(i);

        	   lotDetails.setChecked( false );

           }
        }
        
        if( selectedLotsList != null )
        {
           for(int i=0; i< selectedLotsList.size(); i++ )
           {
        	   LotDetails lotDetails = ( LotDetails)selectedLotsList.get(i);
        	   lotDetails.setChecked( false );
           }
        }
        splInstructions = null;
        noOfBoxes ="";
        wayBillNo ="";
        grossWeight = "";
    }


	public int getPackingSlipId() {
		return packingSlipId;
	}

	public void setPackingSlipId(int packingSlipId) {
		this.packingSlipId = packingSlipId;
	}

	public String getPackingSlipNumber() {
		return packingSlipNumber;
	}

	public void setPackingSlipNumber(String packingSlipNumber) {
		this.packingSlipNumber = packingSlipNumber;
	}

	public String getFromVendorName() {
		return fromVendorName;
	}

	public void setFromVendorName(String fromVendorName) {
		this.fromVendorName = fromVendorName;
	}

	public String getToVendorName() {
		return toVendorName;
	}

	public void setToVendorName(String toVendorName) {
		this.toVendorName = toVendorName;
	}

	public Address getFromAddress() {
		return fromAddress;
	}
	
	public String getFormattedFromAddress() {
        return PackingSlipForm.getFormattedAddress( fromAddress );
	}

	public void setFromAddress(Address fromAddress) {
		this.fromAddress = fromAddress;
	}

	public Address getToAddress() {
		return toAddress;
	}
	
	public String getFormattedToAddress() {
		return PackingSlipForm.getFormattedAddress( toAddress );
	}

	public void setToAddress(Address toAddress) {
		this.toAddress = toAddress;
	}

	public String getNoOfBoxes() {
		return noOfBoxes;
	}

	public void setNoOfBoxes(String noOfBoxes) {
		this.noOfBoxes = noOfBoxes;
	}

	public String getGrossWeight() {
		return grossWeight;
	}

	public void setGrossWeight(String grossWeight) {
		this.grossWeight = grossWeight;
	}

	public String getWayBillNo() {
		return wayBillNo;
	}

	public void setWayBillNo(String wayBillNo) {
		this.wayBillNo = wayBillNo;
	}

	public String getShipDate() {
		return shipDate;
	}

	public void setShipDate(String shipDate) {
		this.shipDate = shipDate;
	}

	public String getShippingMethod() {
		return shippingMethod;
	}

	public void setShippingMethod(String shippingMethod) {
		this.shippingMethod = shippingMethod;
	}

	public String getShippingAccount() {
		return shippingAccount;
	}

	public void setShippingAccount(String shippingAccount) {
		this.shippingAccount = shippingAccount;
	}

	public ArrayList<LotDetails> getSelectedLotsList() {
		return selectedLotsList;
	}

	public void setSelectedLotsList(ArrayList<LotDetails> selectedLotsList) {
		this.selectedLotsList = selectedLotsList;
	}

	public int getToVendorId() {
		return toVendorId;
	}

	public void setToVendorId(int toVendorId) {
		this.toVendorId = toVendorId;
	}

	public int getLotId() {
		return lotId;
	}
	public void setLotId(int lotId) {
		this.lotId = lotId;
	}
	public String getProcessType() {
		return processType;
	}
	public void setProcessType(String processType) {
		this.processType = processType;
	}

    public String getBaseprocessType() {
        return baseprocessType;
    }

    public void setBaseprocessType(String baseprocessType) {
        this.baseprocessType = baseprocessType;
    }

    public int getProcessStepId() {
		return processStepId;
	}
	public void setProcessStepId(int processStepId) {
		this.processStepId = processStepId;
	}
	public int getLocationId() {
		return locationId;
	}
	public void setLocationId(int locationId) {
		this.locationId = locationId;
	}

    public String getSplInstructions() {
        return splInstructions;
    }

    public void setSplInstructions(String splInstructions) {
        this.splInstructions = splInstructions;
    }

    public ClientInfo getClientInfo() {
        return clientInfo;
    }

    public void setClientInfo(ClientInfo clientInfo) {
        this.clientInfo = clientInfo;
    }
    public String getClientAddressXMLFormatted()
    {
        return PackingSlipForm.getXMLFormattedClientAddress( clientInfo.getAddress() );
    }
     public String getFromVendorAddressXMLFormatted()
    {
        return PackingSlipForm.getXMLFormattedAddress( fromAddress );
    }
     public String getToVendorAddressXMLFormatted()
    {
        return PackingSlipForm.getXMLFormattedAddress( toAddress );
    }
    public String getClientAddrWithOutEmailObjFormatted()
	{
        Address add = clientInfo.getAddress();
        StringBuffer formatAddress = new StringBuffer();

        formatAddress.append ( ( ( add.getAddress1() == null ) || ( ( add.getAddress1().trim().length() == 0 ) ) ) ? "" :"<BR>" +  add.getAddress1() );
        formatAddress.append ( ( ( add.getAddress2() == null ) || ( ( add.getAddress2().trim().length() == 0 ) ) ) ? "" :"<BR>" + add.getAddress2() );
        formatAddress.append ( ( ( add.getAddress3() == null ) || ( ( add.getAddress3().trim().length() == 0 ) ) ) ? "" : "<BR>" + add.getAddress3() );
        formatAddress.append ( ( ( add.getAddress4() == null ) || ( ( add.getAddress4().trim().length() == 0 ) ) ) ? "" : "<BR>" + add.getAddress4() );
        //formatAddress.append ( ( ( add.getCity() == null ) || ( add.getCity().trim().length()==0 ) ) ? "" : "<BR>" +  add.getCity() );
        String formatState = PackingSlipForm.getFormatedCityState(add);
        if ( formatState.trim().length() !=0 )
           formatAddress.append ("<BR>"+formatState);
        formatAddress.append ( ( ( add.getPhoneNumber() != null ) && ( add.getPhoneNumber().trim().length() > 0 ) ) ?  "<BR>Tel: "+ add.getPhoneNumber() : "" );
        formatAddress.append ( ( ( add.getFaxNumber() != null ) && ( add.getFaxNumber().trim().length() > 0 ) ) ?  "<BR>Fax: "+ add.getFaxNumber() : "" );

        return formatAddress.toString() ;
	}
}
